package circular_buffer;


public class SimpleCircularBuffer<T> extends AbstractCircularBuffer<T> {
	
	public SimpleCircularBuffer(int maxSize) {
		this.maxSize = maxSize;
	}
	
	@Override
	public void put(T elem) {
		 synchronized (this) {
	            while(isFull()){
	                try {
	                    wait();
	                } catch (InterruptedException e) {
	                    e.printStackTrace();
	                }
	                
	            }
	            buffer.addLast(elem);
	            notifyAll();
	        }
	}

	@Override
	public T get() {
		synchronized (this) {
            while (buffer.isEmpty()){
                try {
                    wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
         }   
         T result = buffer.removeFirst();
         notifyAll();
         return result;
		}
	}
	
	
}
